

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/boshi.jpeg">
  <link rel="icon" type="image/png" href="/img/boshi.jpeg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="wangpf">
  <meta name="keywords" content="">
  <title>Webpack入门配置总结 - wpf的博客</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/foundation.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_6peoq002giu.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.1.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>Wangpf's blog</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/article.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2020-12-18 16:42" pubdate>
      2020年12月18日 下午
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.5k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      22
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">Webpack入门配置总结</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h2><p> 我的配置版本号如下:</p>
 <div class="hljs"><pre><code class="hljs json">&quot;devDependencies&quot;: &#123;
   &quot;css-loader&quot;: &quot;^3.2.0&quot;,
   &quot;dart-sass&quot;: &quot;^1.23.7&quot;,
   &quot;file-loader&quot;: &quot;^5.0.2&quot;,
   &quot;html-webpack-plugin&quot;: &quot;^3.2.0&quot;,
   &quot;less&quot;: &quot;^3.10.3&quot;,
   &quot;less-loader&quot;: &quot;^5.0.0&quot;,
   &quot;mini-css-extract-plugin&quot;: &quot;^0.8.0&quot;,
   &quot;sass-loader&quot;: &quot;^8.0.0&quot;,
   &quot;style-loader&quot;: &quot;^1.0.1&quot;,
   &quot;webpack&quot;: &quot;^4.41.2&quot;,
   &quot;webpack-cli&quot;: &quot;^3.3.10&quot;,
   &quot;webpack-dev-server&quot;: &quot;^3.9.0&quot;
 &#125;,</code></pre></div>

<blockquote>
<p> 参考文档：webpack官方文档 , 在配置每一部分时候我会把链接发在里面</p>
</blockquote>
<h2 id="package-json中配置build"><a href="#package-json中配置build" class="headerlink" title="package.json中配置build"></a>package.json中配置build</h2> <div class="hljs"><pre><code class="hljs json">&quot;scripts&quot;: &#123;
  &quot;build&quot;: &quot;rm -rf dist &amp;&amp; webpack&quot;
&#125;,</code></pre></div>



<h2 id="初始化-webpack-config-js"><a href="#初始化-webpack-config-js" class="headerlink" title="初始化 webpack.config.js"></a>初始化 webpack.config.js</h2><h3 id="模式的区别："><a href="#模式的区别：" class="headerlink" title="模式的区别："></a>模式的区别：</h3> <div class="hljs"><pre><code class="hljs js"><span class="hljs-built_in">module</span>.exports = &#123;
  mode: <span class="hljs-string">&#x27;development&#x27;</span>  <span class="hljs-comment">// 开发者模式  注意去观察 dist/main.js  会发现有许多注释并没有被压缩</span>
&#125;;</code></pre></div>

 <div class="hljs"><pre><code class="hljs js"><span class="hljs-built_in">module</span>.exports = &#123;
  mode: <span class="hljs-string">&#x27;production&#x27;</span>  <span class="hljs-comment">// 生产模式  去观察 dist/main.js  代码都被压缩了，</span>
&#125;;</code></pre></div>



<h3 id="入口文件和出口文件配置："><a href="#入口文件和出口文件配置：" class="headerlink" title="入口文件和出口文件配置："></a>入口文件和出口文件配置：</h3> <div class="hljs"><pre><code class="hljs js"><span class="hljs-keyword">var</span> path = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;path&#x27;</span>);

<span class="hljs-built_in">module</span>.exports = &#123;
  mode: <span class="hljs-string">&#x27;development&#x27;</span>,   <span class="hljs-comment">// 开发者模式</span>
  entry: <span class="hljs-string">&#x27;./src/index.js&#x27;</span>,  <span class="hljs-comment">// 打包的入口文件</span>
  output: &#123;
    path: path.resolve(__dirname, <span class="hljs-string">&#x27;dist&#x27;</span>),  <span class="hljs-comment">// 可用不用写，默认是dist文件</span>
       filename: <span class="hljs-string">&#x27;index.[contenthash].js&#x27;</span>  <span class="hljs-comment">// 打包出口文件名， 以 index.20位随机数/字母.js以文件名</span>

  &#125;
&#125;;</code></pre></div>





<h2 id="webpack插件自动生成HTML："><a href="#webpack插件自动生成HTML：" class="headerlink" title="webpack插件自动生成HTML："></a>webpack插件自动生成HTML：</h2><blockquote>
<p> webpack文档链接 ：<a target="_blank" rel="noopener" href="https://webpack.js.org/plugins/html-webpack-plugin/">https://webpack.js.org/plugins/html-webpack-plugin/</a>   和 <a target="_blank" rel="noopener" href="https://github.com/jantimon/html-webpack-plugin#options">https://github.com/jantimon/html-webpack-plugin#options</a></p>
</blockquote>
<p>  这样就会在 dist文件中生成一个 index.html</p>
 <div class="hljs"><pre><code class="hljs bash">npm install --save-dev html-webpack-plugin</code></pre></div>

 <div class="hljs"><pre><code class="hljs js"><span class="hljs-keyword">var</span> HtmlWebpackPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;html-webpack-plugin&#x27;</span>);

<span class="hljs-built_in">module</span>.exports = &#123;
  plugins: [<span class="hljs-keyword">new</span> HtmlWebpackPlugin()]  
&#125;;</code></pre></div>



<p> 配置内容：</p>
 <div class="hljs"><pre><code class="hljs js">plugins: [<span class="hljs-keyword">new</span> HtmlWebpackPlugin(&#123; 
   <span class="hljs-comment">// 可以不写filename这个属性，也默认生成index.html</span>
   <span class="hljs-comment">// 在这里配置title 要在template中的html文件内的title标签配置 &lt;%= htmlWebpackPlugin.options.title %&gt;</span>
   title: <span class="hljs-string">&#x27;Wang-pf&#x27;</span>,
   template: <span class="hljs-string">&#x27;src/assets/index.html&#x27;</span> <span class="hljs-comment">// 生成模板是哪个</span>
 &#125;)]</code></pre></div>





<h2 id="webpack引入CSS："><a href="#webpack引入CSS：" class="headerlink" title="webpack引入CSS："></a>webpack引入CSS：</h2><h3 id="方法一：-用JS来生成style"><a href="#方法一：-用JS来生成style" class="headerlink" title="方法一： 用JS来生成style"></a>方法一： 用JS来生成style</h3><blockquote>
<p>webpack文档链接: <a target="_blank" rel="noopener" href="https://webpack.docschina.org/loaders/css-loader/#getting-started">https://webpack.docschina.org/loaders/css-loader/#getting-started</a></p>
</blockquote>
<p> 先安装依赖插件， 必须要安装style-loader 。</p>
 <div class="hljs"><pre><code class="hljs bash">npm install --save-dev  style-loader css-loader</code></pre></div>



<p> <strong>原理是 webpack默认要把 以.css结尾的放到style标签中。</strong></p>
 <div class="hljs"><pre><code class="hljs js"><span class="hljs-built_in">module</span>: &#123;
   rules: [&#123;
     test: <span class="hljs-regexp">/\.css$/i</span>, <span class="hljs-comment">// 以 .css 结尾的</span>
     use: [<span class="hljs-string">&quot;style-loader&quot;</span>, <span class="hljs-string">&quot;css-loader&quot;</span>], <span class="hljs-comment">// 依赖插件</span>
   
  &#125;, ],
 &#125;</code></pre></div>



<h3 id="方法二：-把CSS抽成文件"><a href="#方法二：-把CSS抽成文件" class="headerlink" title="方法二： 把CSS抽成文件"></a>方法二： 把CSS抽成文件</h3><p> 先安装依赖，</p>
 <div class="hljs"><pre><code class="hljs bash">npm install --save-dev mini-css-extract-plugin</code></pre></div>



<p> 配置</p>
 <div class="hljs"><pre><code class="hljs js"><span class="hljs-keyword">const</span> MiniCssExtractPlugin = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;mini-css-extract-plugin&#x27;</span>);

<span class="hljs-built_in">module</span>.exports = &#123;
  plugins: [
     <span class="hljs-keyword">new</span> MiniCssExtractPlugin(&#123;
      <span class="hljs-comment">// 类似于 webpackOptions.output 中的选项</span>
      <span class="hljs-comment">// 所有选项都是可选的</span>
      filename: <span class="hljs-string">&#x27;[name].[contenthash].css&#x27;</span>,
      chunkFilename: <span class="hljs-string">&#x27;[id].[contenthash].css&#x27;</span>,
      ignoreOrder: <span class="hljs-literal">false</span>, <span class="hljs-comment">// 忽略有关顺序冲突的警告</span>
    &#125;),
  ],
  <span class="hljs-built_in">module</span>: &#123;
    rules: [
      &#123;
        test: <span class="hljs-regexp">/\.css$/</span>,
       use: [&#123;
          loader: MiniCssExtractPlugin.loader,
          options: &#123;
            <span class="hljs-comment">// 你可以在这里指定特定的 publicPath</span>
            <span class="hljs-comment">// 默认情况下使用 webpackOptions.output 中的 publicPath</span>
            publicPath: <span class="hljs-string">&#x27;../&#x27;</span>,
          &#125;,
        &#125;,
        <span class="hljs-string">&#x27;css-loader&#x27;</span>,
      ],
      &#125;,
    ],
  &#125;,
&#125;;
</code></pre></div>







<h2 id="webpack-dev-server-的使用"><a href="#webpack-dev-server-的使用" class="headerlink" title="webpack dev-server 的使用"></a>webpack dev-server 的使用</h2><blockquote>
<p>webpack dev-server文档链接：<a target="_blank" rel="noopener" href="https://www.webpackjs.com/guides/development/">https://www.webpackjs.com/guides/development/</a>    </p>
</blockquote>
<ol>
<li><p>安装插件</p>
<div class="hljs"><pre><code class="hljs bash">npm install --save-dev webpack-dev-server</code></pre></div>
</li>
<li><p>webpack.config.js 配置</p>
<div class="hljs"><pre><code class="hljs js">devServer: &#123;
	contentBase: <span class="hljs-string">&#x27;./dist&#x27;</span>
&#125;,</code></pre></div></li>
<li><p>在package.json 配置以下 start</p>
<div class="hljs"><pre><code class="hljs bash"><span class="hljs-string">&quot;start&quot;</span>: <span class="hljs-string">&quot;webpack-dev-server --open&quot;</span>,</code></pre></div>



</li>
</ol>
<p> 在 npm start 的时候发现 报错， 报错原因是：<a target="_blank" rel="noopener" href="https://stackoverflow.com/questions/59611597/error-cannot-find-module-webpack-cli-bin-config-yargs">Error: Cannot find module ‘webpack-cli/bin/config-yargs’</a></p>
<p> 解决方法是：把版本号改一下  如下：</p>
 <div class="hljs"><pre><code class="hljs json">&quot;webpack&quot;: &quot;^4.41.2&quot;,
&quot;webpack-cli&quot;: &quot;^3.3.10&quot;,
&quot;webpack-dev-server&quot;: &quot;^3.9.0&quot;</code></pre></div>





<h2 id="不同模式使用不同的-webpack-config"><a href="#不同模式使用不同的-webpack-config" class="headerlink" title="不同模式使用不同的 webpack  config"></a>不同模式使用不同的 webpack  config</h2><blockquote>
<p>我们已经知道模式有 开发者模式(development) 和 生产模式(production)  ,那么我们应该在不同模式中选用不同的插件来使用。</p>
<p>比如： 在生产模式production中，引入CSS方法使用style， 因为这样不同生成一个CSS文件，使得效率变高。如果是开发者模式 ，那么我们就需要把CSS抽成文件。</p>
</blockquote>
<p> 创建一个webpack配置文件：webpack.config.prod.js  用在生产模式时使用。</p>
<p> 创建一个webpack配置文件： webpack.config.base.js  用于开发和生产模式的共同属性</p>
<p> 并在package.json文件中重新配置build。</p>
 <div class="hljs"><pre><code class="hljs json">&quot;build&quot;: &quot;rm -rf dist &amp;&amp; webpack --config webpack.config.prod.js&quot;</code></pre></div>





<h2 id="webpack-loader-和-webpack-plugin-的区别"><a href="#webpack-loader-和-webpack-plugin-的区别" class="headerlink" title="webpack loader   和 webpack  plugin 的区别"></a>webpack loader   和 webpack  plugin 的区别</h2><ul>
<li>loader （加载器） ： 用于加载某些文件，比如加载JS文件，可以把JS转换为低版本支持的js, 又比如CSS,使用相应的loder加载，可以把CSS放到页面上style标签中或者其他处理。也可以用来加载图片，可以对图片进行优化。</li>
<li>plugin （插件）： 扩展webpack功能的，比如使用 HtmlWebpackPlugin 插件用来生成html文件， 使用 miniCssExtractPlugin 插件用来生成CSS文件等。</li>
</ul>
<h2 id="引入-sass"><a href="#引入-sass" class="headerlink" title="引入 sass"></a>引入 sass</h2><blockquote>
<p>参考链接：<a target="_blank" rel="noopener" href="https://webpack.docschina.org/loaders/sass-loader/">https://webpack.docschina.org/loaders/sass-loader/</a></p>
</blockquote>
<p>  这里使用 datr-sass  不使用node-sass（已过时）</p>
 <div class="hljs"><pre><code class="hljs bash">npm install sass-loader dart-sass --save-dev</code></pre></div>



<p> webpakc.config配置：</p>
 <div class="hljs"><pre><code class="hljs js">rules: [&#123;
     test: <span class="hljs-regexp">/\.scss$/i</span>,
     use: [
       <span class="hljs-string">&quot;style-loader&quot;</span>,
       <span class="hljs-string">&quot;css-loader&quot;</span>,
       &#123;
         loader: <span class="hljs-string">&quot;sass-loader&quot;</span>,
         options: &#123;
           <span class="hljs-comment">// `dart-sass` 是首选</span>
           implementation: <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;dart-sass&quot;</span>),
         &#125;,
       &#125;,
     ],
&#125;, ],</code></pre></div>



<p> 把css文件改为scss文件即可使用。</p>
<h2 id="引入less"><a href="#引入less" class="headerlink" title="引入less"></a>引入less</h2><blockquote>
<p>文档链接：<a target="_blank" rel="noopener" href="https://webpack.js.org/loaders/less-loader/">https://webpack.js.org/loaders/less-loader/</a></p>
</blockquote>
<p> 安装loader</p>
 <div class="hljs"><pre><code class="hljs bash">npm install less less-loader --save-dev</code></pre></div>



 <div class="hljs"><pre><code class="hljs js">&#123;
    test: <span class="hljs-regexp">/\.less$/</span>,
    loader: [<span class="hljs-string">&quot;style-loader&quot;</span>,<span class="hljs-string">&quot;css-loader&quot;</span>,<span class="hljs-string">&quot;less-loader&quot;</span>], <span class="hljs-comment">// compiles Less to CSS</span>
  &#125;,</code></pre></div>



<p> stylus  和 引入less 方法一致，不再写了。</p>
<h2 id="使用-file-loader-引入图片"><a href="#使用-file-loader-引入图片" class="headerlink" title="使用 file-loader 引入图片"></a>使用 file-loader 引入图片</h2><blockquote>
<p>参考文档: <a target="_blank" rel="noopener" href="https://webpack.js.org/loaders/file-loader/">https://webpack.js.org/loaders/file-loader/</a></p>
</blockquote>
<p> 安装</p>
 <div class="hljs"><pre><code class="hljs bash">npm install file-loader --save-dev</code></pre></div>

<p> 我的版本号：</p>
 <div class="hljs"><pre><code class="hljs json">&quot;file-loader&quot;: &quot;^5.0.2&quot;,</code></pre></div>



<p> webpack.config配置：</p>
 <div class="hljs"><pre><code class="hljs js"><span class="hljs-built_in">module</span>.exports = &#123;
  <span class="hljs-built_in">module</span>: &#123;
    rules: [
      &#123;
        test: <span class="hljs-regexp">/\.(png|jpe?g|gif)$/i</span>,
        use: [
          &#123;
            loader: <span class="hljs-string">&#x27;file-loader&#x27;</span>,
          &#125;,
        ],
      &#125;,
    ],
  &#125;,
&#125;;</code></pre></div>



<p> 然后在html页面中引入就可以了。</p>
<h2 id="webpack-impor-懒加载"><a href="#webpack-impor-懒加载" class="headerlink" title="webpack impor()  懒加载"></a>webpack impor()  懒加载</h2><p> 不多说看代码</p>
<p> inedx.js</p>
 <div class="hljs"><pre><code class="hljs js"><span class="hljs-comment">// index.js</span>
<span class="hljs-keyword">const</span> btn = <span class="hljs-built_in">document</span>.createElement(<span class="hljs-string">&#x27;button&#x27;</span>)
btn.innerText = <span class="hljs-string">&#x27;懒加载&#x27;</span>
btn.onclick = <span class="hljs-function">()=&gt;</span>&#123;
 <span class="hljs-keyword">const</span> promise = <span class="hljs-keyword">import</span>(<span class="hljs-string">&#x27;./lazy.js&#x27;</span>)
  promise.then(<span class="hljs-function">(<span class="hljs-params"><span class="hljs-built_in">module</span></span>)=&gt;</span>&#123;
    <span class="hljs-keyword">const</span> fn = <span class="hljs-built_in">module</span>.default
    fn()
  &#125;,<span class="hljs-function">()=&gt;</span>&#123;
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;懒加载模块加载失败&#x27;</span>)
  &#125;)
&#125;

div.appendChild(btn)</code></pre></div>



<p> lazy.js</p>
 <div class="hljs"><pre><code class="hljs js"><span class="hljs-keyword">export</span>  <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">lazy</span>(<span class="hljs-params"></span>) </span>&#123;
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;我是懒加载陌客&#x27;</span>)
&#125;</code></pre></div>



<p> 上面就是如何使用 import() 来实现懒加载</p>
<p> 用 import()  去加载文件 ，然后得到一个 promise  ， 在成功之后 使用 module.default() 调用 lazy.js 文件</p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                <div class="post-meta mr-3">
                  <i class="iconfont icon-category"></i>
                  
                  <a class="hover-with-bg" href="/categories/webpack/">webpack</a>
                  
                </div>
                
                
                <div class="post-meta">
                  <i class="iconfont icon-tags"></i>
                  
                  <a class="hover-with-bg" href="/tags/webpack/">webpack</a>
                  
                </div>
                
              </div>
              
              
              <div class="post-prevnext row">
                <article class="post-prev col-6">
                  
                  
                  <a href="/2020/12/20/35-Vue%E4%BF%A9%E4%B8%AA%E7%89%88%E6%9C%AC/">
                    <i class="iconfont icon-arrowleft"></i>
                    <span class="hidden-mobile">vue俩个版本：runtime-compiler和 runtime-only 的区别</span>
                    <span class="visible-mobile">上一篇</span>
                  </a>
                  
                </article>
                <article class="post-next col-6">
                  
                  
                  <a href="/2020/12/17/33-MVC/">
                    <span class="hidden-mobile">JavaScript中的MVC</span>
                    <span class="visible-mobile">下一篇</span>
                    <i class="iconfont icon-arrowright"></i>
                  </a>
                  
                </article>
              </div>
              
            </div>

            
            <!-- Comments -->
            <article class="comments" id="comments">
              
              
  <div id="vcomments"></div>
  <script type="text/javascript">
    function loadValine() {
      addScript('https://cdn.staticfile.org/valine/1.4.14/Valine.min.js', function () {
        new Valine({
          el: "#vcomments",
          app_id: "hjxsDRXYScicliqD8I8JqoTu-gzGzoHsz",
          app_key: "qUcAEReEqeEVp5wwXJ41uCCp",
          placeholder: "说点什么",
          path: window.location.pathname,
          avatar: "retro",
          meta: ["nick","mail","link"],
          pageSize: "10",
          lang: "zh-CN",
          highlight: true,
          recordIP: false,
          serverURLs: "",
        });
      });
    }
    waitElementVisible('vcomments', loadValine);
  </script>
  <noscript>Please enable JavaScript to view the <a target="_blank" href="https://valine.js.org" rel="nofollow noopener noopener">comments
      powered by Valine.</a></noscript>


            </article>
            
          </article>
        </div>
      </div>
    </div>
    
    <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
      <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

    </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    
      <script  src="/js/lazyload.js" ></script>
    
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "Webpack入门配置总结&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "always",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  











  

  

  

  

  

  





</body>
</html>
